<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/taglib.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<title>系统模块管理</title>
		<%@ include file="/WEB-INF/jsp/include.jsp"%>
		<script type="text/javascript">
		
		var codeFlag = 0;
		var nameFlag = 0;
	
		$(function(){
			setValue();
		});
		
		//获取父页面的值
		function setValue(){
			var row = parent.$('#tt').treegrid('getSelected');
			if(row != null){
				$('#parentMenuCode').val(row.menuCode);
			}
		}
		
		//code 查重复
		function checkRepeatCode(value){
			var params = new Object();
			params.menuCode = value;
            //params.parentMenuCode = $('#parentMenuCode').val();
			$.ajax({
				type: "POST",
				url: '${path}/system/module/queryByList',
				dataType: "json",
				data: params,
				success: function callback(data){
					if(data.code=="0001"){
						codeFlag = 0;
					}else{
						codeFlag = 1;
						$.messager.alert('操作提示','代码不可用','info',function(){
							$('#menuCode')[0].focus();
						});
					}
				},
				error:function(){
					
				}
			});
		}
		
		//name,code 查重复
		function checkRepeatName(value){
			var row = parent.$('#tt').treegrid('getSelected');
			var params = new Object();
			params.menuName = value;
            params.parentMenuCode = $('#parentMenuCode').val();
//			if(row != null){
//				params.menuName = row.menuName;
//			}
			$.ajax({
				type: "POST",
				url: '${path}/system/module/checkModuleName',
				dataType: "json",
				data: params,
				success: function callback(data){
					if(data.code=="0001"){
						nameFlag = 0;
					}else{
						nameFlag = 1;
						$.messager.alert('操作提示','名称不可用','info',function(){
							$('#menuName')[0].focus();
						});
					}
				},
				error:function(){
					
				}
			});
		}
		//保存增加的数据
		function submit_Add(){

			if(codeFlag == 1){
				checkRepeatCode($('#menuCode').val());
				return;
			}
			if(nameFlag == 1){
				checkRepeatName($('#menuName').val());
				return;
			}
			
			if (!validform("mkForm")) {
				return;
			}

            $.ajax({
				type : "POST",
				url :'${path}/system/module/save',
				dataType : "json",
                data :$('#mkForm').serialize(),
				success : function callback(data) {
					var analyMsg = data;
					if (analyMsg.code != '0000') {
						$.messager.alert('友情提醒', analyMsg.msg, 'info',function() {});
					} else {
//						$.messager.alert("友情提醒", "添加模块成功。", "info",function(){
// 							parent.btnQuery();
//							closeLayer();
//						});
//						$.alert("add", "info", "模块");
                        parent.btnQuery();
                        closeLayer();
					}
				},
				error : function(data, textstatus) {
					//alert("error");
					$.messager.alert('友情提醒', data.responseText, 'info',function(){});
				}
			});
			
		}
		
		</script>
	</head>

  <body  style="margin:0px; padding:0px;" > 
	<%@ include file="/WEB-INF/jsp/loading.jsp" %>
	<div class="easyui-layout" fit="true" >
		<div id="AddDlgDiv" align="center"  style="margin:5px; padding:5px;">
			<form id="mkForm" method="post" >
				<table class="f_table" cellspacing="1">
					<tr>
						<td align="right" class="s_bg" style="width:210px;">
							上级模块代码：
						</td>
						<td align="left" style="width:210px;">
							<input type="text" id="parentMenuCode" name="parentMenuCode" style="width: 210px;" class="easyui-validatebox" />
						</td>
						<td align="right" class="s_bg" style="width:210px;">
							模块代码：
						</td>
						<td align="left" style="width:210px;">
							<input type="text" id="menuCode" name="menuCode" style="width: 210px;" class="easyui-validatebox" onchange="checkRepeatCode(this.value);" data-options="required:true,tipPosition:'left'"/>
						</td>
					</tr>
					<tr>
						<td align="right" class="s_bg" style="width:210px;">
							模块名称：
						</td>
						<td align="left"  style="width: 210px;">
							<input type="text" id="menuName" name="menuName" style="width: 210px;" onchange="checkRepeatName(this.value);" class="easyui-validatebox" data-options="required:true"/>
						</td>
						<td align="right" class="s_bg">
							模块序号：
						</td>
						<td align="left" style="width:210px;">
							<input type="number" id="menuNum" name="menuNum" style="width: 210px;" class="easyui-validatebox" data-options="required:true,tipPosition:'left'"/>
						</td>
					</tr>
					
					<tr>
						<td align="right" class="s_bg">
							模块类型：
						</td>
						<td align="left"  style="width: 210px;">
							<input type="text" id="menuType" name="menuType" style="width: 210px;"class="easyui-validatebox" maxlength="2" data-options="required:true"/>
						</td>
						<td align="right" class="s_bg">
							模块 Url：
						</td>
						<td align="left" style="width:210px;" >
							<input type="text" id="menuUrl" name="menuUrl" style="width: 210px;" />
						</td>
					</tr>
					<tr>
						<td align="right" class="s_bg">
							模块图标：
						</td>
						<td align="left" style="width:210px;" >
							<input type="text" id="moduleIcon" name="moduleIcon" style="width: 210px;" />
						</td>
						<td align="right" class="s_bg">
							模块简称：
						</td>
						<td align="left" style="width:210px;" >
							<input type="text" id="menuDescription" name="menuDescription" class="easyui-validatebox"style="width: 210px;" data-options="required:true,tipPosition:'left'"/>
							<input type="hidden" id="validMark" name = "validMark" value="1"/><!--默认有效 -->
						</td>
					</tr>
					
				</table>
			</form>  
			  <div align="center" style="margin-top: 15px;">
		        	<a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-ok" onclick="submit_Add()">确定</a>
		        	<a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-cancel" onclick="closeLayer();">取消</a>
       		 </div>
		</div>
	</div>
</body>
</html>
